import 'package:favoritecate/core/model/meal_model.dart';
import 'package:flutter/material.dart';

class FYFavorMealViewModel extends ChangeNotifier{
  List<FYMealModel> _favorMeals = [];


  List<FYMealModel> get favorMeals => _favorMeals;

  void addMeal(FYMealModel model){
    //保存收藏的meal
    _favorMeals.add(model);
    notifyListeners();
  }

  void removeMeal(FYMealModel model){
    //取消收藏
    _favorMeals.remove(model);
    notifyListeners();
  }

  bool isFavor(FYMealModel model){
    return _favorMeals.contains(model);
  }

  void handleMeal(FYMealModel model){
    if(isFavor(model)){
      removeMeal(model);
    }else{
      addMeal(model);
    }
  }
}